package cn.net.autocode.platform.config;

import cn.net.autocode.platform.constants.PlatformConstant;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration   //TODO 拦截器注掉了
public class WebConfigurer implements WebMvcConfigurer {

    private final LoginInterceptor loginInterceptor;

    public WebConfigurer(LoginInterceptor loginInterceptor) {
        this.loginInterceptor = loginInterceptor;
    }

    /**
     * 1、设置默认访问页面、404、500页面
     */
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName(PlatformConstant.FORLOGIN_PATH);
    }

    /**
     * 这个方法用来注册拦截器，我们自己写的拦截器需要通过这里添加注册才能生效
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration ir = registry.addInterceptor(loginInterceptor);
        ir.addPathPatterns("/**");
        PlatFormExcludePath.init(ir);

    }
}
